#include "ICollisionTest.h"

#include "../src/icollision.h"

using physicsworks::intersectTriangle;

CPPUNIT_TEST_SUITE_REGISTRATION(ICollisionTest);

void ICollisionTest::setUp()
{
	af0 = new Vec3<float>(1, 0, 1);
	af1 = new Vec3<float>(3, 0, 1);
	af2 = new Vec3<float>(2, 0, 3);
	
	bf0 = new Vec3<float>(2, 2, 0);
	bf1 = new Vec3<float>(3, 2, 0);
	bf2 = new Vec3<float>(2, 3, 0);
	
	cf0 = new Vec3<float>(2, 2, 2);
	cf1 = new Vec3<float>(3, 2, 2);
	cf2 = new Vec3<float>(2, 3, 2);
	
	df0 = new Vec3<float>(4, -1, 2);
	df1 = new Vec3<float>(6, -1, 2);
	df2 = new Vec3<float>(5,  1, 2);
	
	ef0 = new Vec3<float>(1, -1, 2);
	ef1 = new Vec3<float>(3, -1, 2);
	ef2 = new Vec3<float>(2,  1, 2);
	
	ff0 = new Vec3<float>(1, -1, 3);
	ff1 = new Vec3<float>(3, -1, 3);
	ff2 = new Vec3<float>(2,  1, 1);
}

/**
 * 
 * \TODO Perform more intersection tests using triangles in other positions.
 */
void ICollisionTest::testIntersection()
{
	CPPUNIT_ASSERT(intersectTriangle(*af0, *af1, *af2, *bf0, *bf1, *bf2) == false);
	CPPUNIT_ASSERT(intersectTriangle(*af0, *af1, *af2, *cf0, *cf1, *cf2) == false);
	CPPUNIT_ASSERT(intersectTriangle(*af0, *af1, *af2, *df0, *df1, *df2) == false);
	CPPUNIT_ASSERT(intersectTriangle(*af0, *af1, *af2, *ef0, *ef1, *ef2) == true);
	CPPUNIT_ASSERT(intersectTriangle(*af0, *af1, *af2, *ff0, *ff1, *ff2) == true);
}

void ICollisionTest::tearDown()
{
	delete af0; delete af1; delete af2;
	delete bf0; delete bf1; delete bf2;
	delete cf0; delete cf1; delete cf2;
	delete df0; delete df1; delete df2;
	delete ef0; delete ef1; delete ef2;
	delete ff0; delete ff1; delete ff2;
}
